package com.isczy.eduservice.controller;

import com.isczy.eduservice.entity.vo.UserVo;
import com.isczy.servicebase.exceptionHandler.MyException;
import com.isczy.utils.DataResult;
import com.isczy.utils.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/********************************************
 * @Brief:登录控制器
 * @Version: 1.0
 * @Date: 2020年12月28日 15:35:35
 * @Author: ChangZiYang
 * ******************************************
 */
@Api(description = "登录控制器")
@RestController
@RequestMapping("/eduservice/user")
public class EduLoginController {

    @ApiOperation(value = "登录")
    @PostMapping("login")
    public DataResult login(@RequestBody UserVo user){
        try {
            return DataResult.builder()
                    .data("token","admin")
                    .successBuild();
        }catch (Exception e){
            throw MyException.builder()
                    .exception(e)
                    .code(ResultCode.ERROR)
                    .className(getClass().getName())
                    .methodName(Thread.currentThread().getStackTrace()[1].getMethodName())
                    .message("登录失败")
                    .params(user)
                    .build();
        }
    }

    @ApiOperation(value = "根据令牌查询用户信息")
    @GetMapping("info")
    public DataResult info(UserVo user){
        try {
            return DataResult.builder()
                    .data("roles","admin")
                    .data("name","admin")
                    .data("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif")
                    .successBuild();
        } catch (Exception e) {
            throw MyException.builder()
                    .exception(e)
                    .code(ResultCode.ERROR)
                    .className(getClass().getName())
                    .methodName(Thread.currentThread().getStackTrace()[1].getMethodName())
                    .message("根据令牌查询用户信息失败")
                    .params(user)
                    .build();
        }
    }
}
